/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import database.worker.DBEventWorker;
import dto.Event;
import dto.ImageEvent;
import dto.Metadata;
import dto.TextEvent;
import dto.Track;
import dto.VideoEvent;
import gui.cell.TrackEventCellRenderer;
import gui.event.AddEditEventWindow;
import gui.event.ImageEventPanel;
import gui.event.TextEventPanel;
import gui.event.VideoEventPanel;
import gui.tabpane.HeaderPanel;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.MouseEvent;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import map.MapManager;
import org.jdesktop.swingx.mapviewer.GeoPosition;

/**
 * The TrackPanel shows detailed information about the track and offers possibilites to show its events
 * 
 * @author Pascal
 */
public class TrackPanel extends javax.swing.JPanel {
    
    private Icon iconText;
    private Icon iconImage;
    private Icon iconVideo;
    
    private Track track;
    private MapManager mm;
    
    /**
     * Creates new form TrackPanel
     */
    public TrackPanel() {       
        iconText = new ImageIcon(getClass().getResource("/gui/resources/text_dropcaps.png"));
        iconImage = new ImageIcon(getClass().getResource("/gui/resources/picture.png"));
        iconVideo = new ImageIcon(getClass().getResource("/gui/resources/film.png"));
        //timelineListModel = new DefaultListModel<>();
        
        
        initComponents();
        
        //calculate the seperators left inset for different locales
        GridBagLayout layout = (GridBagLayout) jPanel2.getLayout();
        GridBagConstraints constraints = layout.getConstraints(jSeparator3);
        constraints.insets.left = (int)jLabel1.getPreferredSize().getWidth() + 10;
        layout.setConstraints(jSeparator3, constraints);
        
        constraints = layout.getConstraints(jSeparator4);
        constraints.insets.left = (int)jLabel50.getPreferredSize().getWidth() + 10;
        layout.setConstraints(jSeparator4, constraints);
        
        constraints = layout.getConstraints(jSeparator5);
        constraints.insets.left = (int)jLabel69.getPreferredSize().getWidth() + 10;
        layout.setConstraints(jSeparator5, constraints);
        
        tabPane.setTabComponentAt(0, new HeaderPanel(tabPane, new ImageIcon(getClass().getResource("/gui/resources/world.png")), false));
        
    }
    
    public Track getTrack() {
        return track;
    }
    
    /**
     * Gets the currently selected Event in the timeline
     * 
     * @return the Event if any is selected else null
     */
    public Event getSelectedEvent() {
        Object obj = listTimeline.getSelectedValue();
        
        if (obj != null) {
            return (Event)obj;
        }
        else {
            return null;
        }
    }
    
    public void createNewEvent(){
        if (getTrack() != null) {
            AddEditEventWindow newEventDialog = new AddEditEventWindow(getTrack());
            newEventDialog.setVisible(true);
            newEventDialog.dispose();
           // if (newEventDialog != null){
                //event liste hinzufügen !!!!!!!!!!!!
                //addEvent(newEventDialog.getEvent());
                
            //}
        }        
    }
    
    public void deleteEvent(){
        if (getSelectedEvent() != null) {
            int result = javax.swing.JOptionPane.showConfirmDialog(null, ResourceBundle.getBundle("gui/guilabels").getString("deleteEvent"), ResourceBundle.getBundle("gui/guilabels").getString("deleteEventTitel"), javax.swing.JOptionPane.YES_NO_OPTION);
            if (result == javax.swing.JOptionPane.YES_OPTION) {
                DBEventWorker worker = new DBEventWorker(DBEventWorker.Type.RemoveEvent, getSelectedEvent(), getTrack());
                worker.execute();
            }       
        }           
    }
    
    public void setTrack(Track track) {
        this.track = track;
        
        SimpleDateFormat dateFormatter = new SimpleDateFormat("dd. MMM y");
        SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm");
        
        DecimalFormat intFormat = new DecimalFormat("00");
        DecimalFormat numberFormat = new DecimalFormat("#0.00");
        DecimalFormat tempFormat = new DecimalFormat("#0.0");
        
        for (int i = 1; i < tabPane.getTabCount(); i++) {
            tabPane.remove(i);
        }
        
        labelTrackname.setText(track.getTrackName());
        labelDate.setText(dateFormatter.format(track.getDate().getTime()));
        labelTime.setText(timeFormatter.format(track.getDate().getTime()));
        
        Metadata meta = track.getMetadata();
        labelDistance.setText(numberFormat.format(meta.getDistance()) + " km");
        int hours = (int)(meta.getTime() / 1000f / 60f / 60f);
        int minutes = ((int)(meta.getTime() / 1000f / 60f) % 60);
        labelDuration.setText(intFormat.format(hours) + ":" + intFormat.format(minutes));
        labelTrackProfile.setText(meta.getProfile());
        switch (meta.getRating()) {
            case LOW:
                labelDifficulty.setIcon(new ImageIcon(getClass().getResource("/gui/resources/green_point.png")));
                break;
            case MEDIUM:
                labelDifficulty.setIcon(new ImageIcon(getClass().getResource("/gui/resources/yellow_point.png")));
                break;
            case HIGH:
                labelDifficulty.setIcon(new ImageIcon(getClass().getResource("/gui/resources/red_point.png")));
                break;
        }
        
        labelRestingOpt.setText(meta.getRestingOptions() ? ResourceBundle.getBundle("gui/guilabels").getString("yes") : ResourceBundle.getBundle("gui/guilabels").getString("no"));
        textAreaDesc.setText(meta.getDescription());
        labelDistanceHome.setText(numberFormat.format(meta.getDistanceToHome()) + " km");
        labelDogs.setText(meta.isSuitableForDogs() ? ResourceBundle.getBundle("gui/guilabels").getString("yes") : ResourceBundle.getBundle("gui/guilabels").getString("no"));
        labelGroundCond.setText(meta.getGroundConditions());
        labelBustle.setText(meta.getBustle());
        labelParking.setText(meta.getParking());
        labelCost.setText(numberFormat.format(meta.getExpenses()) + " €");
        labelSigns.setText(meta.getSigns());
        labelTemp.setText(tempFormat.format(meta.getTemperature()) + " °c");
        labelWeatherType.setText(meta.getWeather());
        
        listTimeline.setModel(track.getEvents());
        
        mm = new MapManager(map);
        mm.drawTrack(track.getTrackList());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        tabPane = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jSplitPane1 = new javax.swing.JSplitPane();
        jSplitPane2 = new javax.swing.JSplitPane();
        map = new org.jdesktop.swingx.JXMapKit();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listTimeline = new javax.swing.JList();
        jPanel4 = new javax.swing.JPanel();
        btnPaintAllEvents = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jPanel2 = new javax.swing.JPanel();
        labelTrackname = new javax.swing.JLabel();
        jLabel42 = new javax.swing.JLabel();
        labelDate = new javax.swing.JLabel();
        jLabel44 = new javax.swing.JLabel();
        labelTime = new javax.swing.JLabel();
        jLabel46 = new javax.swing.JLabel();
        labelDistance = new javax.swing.JLabel();
        jLabel48 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        textAreaDesc = new javax.swing.JTextArea();
        jLabel50 = new javax.swing.JLabel();
        jLabel51 = new javax.swing.JLabel();
        labelTemp = new javax.swing.JLabel();
        labelWeatherType = new javax.swing.JLabel();
        jLabel57 = new javax.swing.JLabel();
        labelDuration = new javax.swing.JLabel();
        jLabel59 = new javax.swing.JLabel();
        labelGroundCond = new javax.swing.JLabel();
        jLabel61 = new javax.swing.JLabel();
        labelBustle = new javax.swing.JLabel();
        jLabel63 = new javax.swing.JLabel();
        labelDogs = new javax.swing.JLabel();
        jLabel65 = new javax.swing.JLabel();
        labelTrackProfile = new javax.swing.JLabel();
        jLabel67 = new javax.swing.JLabel();
        labelDifficulty = new javax.swing.JLabel();
        jLabel69 = new javax.swing.JLabel();
        labelParking = new javax.swing.JLabel();
        jLabel71 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator4 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jSeparator5 = new javax.swing.JSeparator();
        labelCost = new javax.swing.JLabel();
        jSeparator6 = new javax.swing.JSeparator();
        jLabel4 = new javax.swing.JLabel();
        labelDistanceHome = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        labelRestingOpt = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        labelSigns = new javax.swing.JLabel();

        setLayout(new java.awt.CardLayout());

        jPanel1.setLayout(new java.awt.CardLayout());

        jSplitPane1.setDividerLocation(370);
        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        jSplitPane2.setDividerLocation(250);

        map.setDefaultProvider(org.jdesktop.swingx.JXMapKit.DefaultProviders.OpenStreetMaps);
        map.setMiniMapVisible(false);
        jSplitPane2.setRightComponent(map);

        jPanel3.setLayout(new java.awt.BorderLayout());

        listTimeline.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listTimeline.setCellRenderer(new TrackEventCellRenderer());
        listTimeline.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listTimelineMouseClicked(evt);
            }
        });
        listTimeline.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listTimelineValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(listTimeline);

        jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jPanel4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(133, 133, 133)));
        jPanel4.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 1));

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("gui/guilabels"); // NOI18N
        btnPaintAllEvents.setText(bundle.getString("paintallevents")); // NOI18N
        btnPaintAllEvents.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPaintAllEventsActionPerformed(evt);
            }
        });
        jPanel4.add(btnPaintAllEvents);

        jPanel3.add(jPanel4, java.awt.BorderLayout.PAGE_END);

        jSplitPane2.setLeftComponent(jPanel3);

        jSplitPane1.setTopComponent(jSplitPane2);

        jPanel2.setLayout(new java.awt.GridBagLayout());

        labelTrackname.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        labelTrackname.setText("Trackname");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(5, 7, 0, 0);
        jPanel2.add(labelTrackname, gridBagConstraints);

        jLabel42.setText(bundle.getString("date")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 3);
        jPanel2.add(jLabel42, gridBagConstraints);

        labelDate.setText("14.09.2013");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(labelDate, gridBagConstraints);

        jLabel44.setText(bundle.getString("time")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 3);
        jPanel2.add(jLabel44, gridBagConstraints);

        labelTime.setText("10:05");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(labelTime, gridBagConstraints);

        jLabel46.setText(bundle.getString("tracklenght")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 3);
        jPanel2.add(jLabel46, gridBagConstraints);

        labelDistance.setText("5,0 km");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(labelDistance, gridBagConstraints);

        jLabel48.setText(bundle.getString("description")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 3);
        jPanel2.add(jLabel48, gridBagConstraints);

        textAreaDesc.setEditable(false);
        textAreaDesc.setColumns(20);
        textAreaDesc.setLineWrap(true);
        textAreaDesc.setRows(5);
        jScrollPane3.setViewportView(textAreaDesc);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 11;
        gridBagConstraints.gridwidth = 8;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 5, 5);
        jPanel2.add(jScrollPane3, gridBagConstraints);

        jLabel50.setText(bundle.getString("weather")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(jLabel50, gridBagConstraints);

        jLabel51.setText(bundle.getString("temperature")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(jLabel51, gridBagConstraints);

        labelTemp.setText("15,3 °c");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 7;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(labelTemp, gridBagConstraints);

        labelWeatherType.setText("Sunny");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(labelWeatherType, gridBagConstraints);

        jLabel57.setText(bundle.getString("duration")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 3);
        jPanel2.add(jLabel57, gridBagConstraints);

        labelDuration.setText("3:20 h");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(labelDuration, gridBagConstraints);

        jLabel59.setText(bundle.getString("groundconditions")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(jLabel59, gridBagConstraints);

        labelGroundCond.setText("Mud");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 5);
        jPanel2.add(labelGroundCond, gridBagConstraints);

        jLabel61.setText(bundle.getString("peopleontrack")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(jLabel61, gridBagConstraints);

        labelBustle.setText("many");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 5);
        jPanel2.add(labelBustle, gridBagConstraints);

        jLabel63.setText(bundle.getString("parkingpossibilities")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(jLabel63, gridBagConstraints);

        labelDogs.setText("Yes");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 5);
        jPanel2.add(labelDogs, gridBagConstraints);

        jLabel65.setText(bundle.getString("trackprofile")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 3);
        jPanel2.add(jLabel65, gridBagConstraints);

        labelTrackProfile.setText("flat");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(labelTrackProfile, gridBagConstraints);

        jLabel67.setText(bundle.getString("difficulty")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 3);
        jPanel2.add(jLabel67, gridBagConstraints);

        labelDifficulty.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/resources/green_point.png"))); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(labelDifficulty, gridBagConstraints);

        jLabel69.setText(bundle.getString("special")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(jLabel69, gridBagConstraints);

        labelParking.setText("enough");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 5);
        jPanel2.add(labelParking, gridBagConstraints);

        jLabel71.setText(bundle.getString("dogssuitable")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(jLabel71, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 8;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(8, 7, 8, 7);
        jPanel2.add(jSeparator1, gridBagConstraints);

        jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridheight = 9;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(jSeparator2, gridBagConstraints);

        jLabel1.setText(bundle.getString("general")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 3);
        jPanel2.add(jLabel1, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 48, 3, 3);
        jPanel2.add(jSeparator3, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 53, 3, 3);
        jPanel2.add(jSeparator4, gridBagConstraints);

        jLabel2.setText(bundle.getString("cost")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(jLabel2, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 42, 3, 3);
        jPanel2.add(jSeparator5, gridBagConstraints);

        labelCost.setText("20,0 €");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 5);
        jPanel2.add(labelCost, gridBagConstraints);

        jSeparator6.setOrientation(javax.swing.SwingConstants.VERTICAL);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridheight = 9;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(jSeparator6, gridBagConstraints);

        jLabel4.setText(bundle.getString("distancehome")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(jLabel4, gridBagConstraints);

        labelDistanceHome.setText("4,5 km");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 5);
        jPanel2.add(labelDistanceHome, gridBagConstraints);

        jLabel6.setText(bundle.getString("restingoptions")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 3);
        jPanel2.add(jLabel6, gridBagConstraints);

        labelRestingOpt.setText("Yes");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(labelRestingOpt, gridBagConstraints);

        jLabel8.setText(bundle.getString("sign")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel2.add(jLabel8, gridBagConstraints);

        labelSigns.setText("Not really...");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 5);
        jPanel2.add(labelSigns, gridBagConstraints);

        jScrollPane2.setViewportView(jPanel2);

        jSplitPane1.setBottomComponent(jScrollPane2);

        jPanel1.add(jSplitPane1, "card2");

        tabPane.addTab("Track", jPanel1);

        add(tabPane, "card2");
    }// </editor-fold>//GEN-END:initComponents

    private void listTimelineMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listTimelineMouseClicked
        if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
            //left click and double click
            Event e = getSelectedEvent();
            
            if (e == null) {
                return;
            }
            
            switch (e.getEventType()) {
                case Image:
                    tabPane.add(e.getEventName(), new ImageEventPanel((ImageEvent)e));
                    tabPane.setTabComponentAt(tabPane.getTabCount() - 1, new HeaderPanel(tabPane, iconImage));
                    break;
                case Text:
                    tabPane.add(e.getEventName(), new TextEventPanel((TextEvent)e));
                    tabPane.setTabComponentAt(tabPane.getTabCount() - 1, new HeaderPanel(tabPane, iconText));
                    break;
                case Video:
                    tabPane.add(e.getEventName(), new VideoEventPanel((VideoEvent)e));
                    tabPane.setTabComponentAt(tabPane.getTabCount() - 1, new HeaderPanel(tabPane, iconVideo));
                    break;
            }
            
            tabPane.setSelectedIndex(tabPane.getTabCount() - 1);
        }
    }//GEN-LAST:event_listTimelineMouseClicked

    private void btnPaintAllEventsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPaintAllEventsActionPerformed
        List<GeoPosition> eventPositions = new ArrayList<>();
        
        DefaultListModel<Event> events = track.getEvents();
        for (int i = 0; i < events.size(); i++) {
            eventPositions.add(events.get(i).getPos().toGeoPosition());
        }
        
        mm.paintGPSPoints(eventPositions);
    }//GEN-LAST:event_btnPaintAllEventsActionPerformed

    private void listTimelineValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listTimelineValueChanged
        if (listTimeline.getSelectedValue() != null)
            mm.paintGPSPoint(((Event)listTimeline.getSelectedValue()).getPos().toGeoPosition());
    }//GEN-LAST:event_listTimelineValueChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnPaintAllEvents;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel42;
    private javax.swing.JLabel jLabel44;
    private javax.swing.JLabel jLabel46;
    private javax.swing.JLabel jLabel48;
    private javax.swing.JLabel jLabel50;
    private javax.swing.JLabel jLabel51;
    private javax.swing.JLabel jLabel57;
    private javax.swing.JLabel jLabel59;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel61;
    private javax.swing.JLabel jLabel63;
    private javax.swing.JLabel jLabel65;
    private javax.swing.JLabel jLabel67;
    private javax.swing.JLabel jLabel69;
    private javax.swing.JLabel jLabel71;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JLabel labelBustle;
    private javax.swing.JLabel labelCost;
    private javax.swing.JLabel labelDate;
    private javax.swing.JLabel labelDifficulty;
    private javax.swing.JLabel labelDistance;
    private javax.swing.JLabel labelDistanceHome;
    private javax.swing.JLabel labelDogs;
    private javax.swing.JLabel labelDuration;
    private javax.swing.JLabel labelGroundCond;
    private javax.swing.JLabel labelParking;
    private javax.swing.JLabel labelRestingOpt;
    private javax.swing.JLabel labelSigns;
    private javax.swing.JLabel labelTemp;
    private javax.swing.JLabel labelTime;
    private javax.swing.JLabel labelTrackProfile;
    private javax.swing.JLabel labelTrackname;
    private javax.swing.JLabel labelWeatherType;
    private javax.swing.JList listTimeline;
    private org.jdesktop.swingx.JXMapKit map;
    private javax.swing.JTabbedPane tabPane;
    private javax.swing.JTextArea textAreaDesc;
    // End of variables declaration//GEN-END:variables
    //private DefaultListModel<ITrackEventData> timelineListModel;
}
